package com.daylightrobbery.server.packet;

import com.daylightrobbery.server.packet.type.DataPacket;
import com.daylightrobbery.utils.ObjectMapperUtil;

public class GamePacket {

    public static final int ACK_TYPE = -1000;
    private Long id;  //数据包id
    private String uid;     // 用户uid
    private int type;    // 数据包类型

    private String data;    // 数据体

    public Long getId() {
        return id;
    }

    public GamePacket setId(Long id) {
        this.id = id;
        return this;
    }

    public GamePacket Ack(){
        return new GamePacket().setId(this.id).setUid(this.uid).setType(-1000);
    }

    public String getUid() {
        return uid;
    }

    public GamePacket setUid(String uid) {
        this.uid = uid;
        return this;
    }

    public int getType() {
        return type;
    }

    public GamePacket setType(int type) {
        this.type = type;
        return this;
    }

    public String getData() {
        return data;
    }

    public GamePacket setData(String data) {
        this.data = data;
        return this;
    }
    public GamePacket setData(DataPacket data) {
        this.type = data.getType();
        this.data = ObjectMapperUtil.toJSON(data);
        return this;
    }

    @Override
    public String toString() {
        return "GamePacket{" +
                "id=" + id +
                ", uid='" + uid + '\'' +
                ", type=" + type +
                ", data='" + data + '\'' +
                '}';
    }
}
